<template>
	<view class="page">

		<view class="uni-list">
			<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(value,key) in listData" :key="key" >
				<view class="uni-media-list">
					<view class="uni-media-list-body">
						<view class="uni-media-list-text-top">订单编号:{{value.bill_no}}</view>
						<view class="uni-media-list-text-bottom">
							<text>{{value.desc}}</text>
							<text>{{value.created_at}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var dateUtils = require('../../common/util.js').dateUtils;
	import {
		mapState,
		mapMutations
	} from 'vuex'

	export default {
		data() {
			return {
				banner: {},
				listData: [],
				last_page:'',
				page: 1,
				reload: false
			}
		},
		onLoad() {
			this.getList();
		
		},

		onPullDownRefresh() {
			this.reload = true;
			this.page = 1;
			this.getList();
		},
		onReachBottom() {
			if(this.page<this.last_page){
			  this.getList();
			}
		},
		computed: mapState(['apiUrl', 'token']),
		methods: {
			
			getList() {
				var data = {
					token: this.token,
					type: 0,
					page:1,
					begin_time: '2018-09-01 00:00:00',
					end_time: new Date().format("yyyy-MM-dd hh:mm:ss"),
				};
				if(this.page<this.last_page){
					this.page++;
					data.page = this.page;
					data.time = new Date().getTime() + "";
				} 
				uni.request({
					url: this.apiUrl + 'app/moneylog',
					method: 'POST',
					data: data,
					success: (data) => {

						if (data.data.code == 1) {
							let lists = data.data.data.itemspage.data;
							this.last_page = data.data.data.itemspage.last_page;
				
							let list = this.setTime(lists);
							this.listData = this.reload ? list : this.listData.concat(list);
							
							this.reload = false;
						}
					},
					fail: (data, code) => {
						console.log('fail' + JSON.stringify(data));
					}
				})
			},
			setTime: function(items) {
				var newItems = [];
				items.forEach((e) => {
					newItems.push({
						desc: e.desc,
						money: e.money,
						id: e.id,
						bill_no: e.bill_no,
						before_money: e.before_money,
						after_money: e.after_money,
						created_at: e.updated_at,
					});
				});
				return newItems;
			}
		},
	}
</script>

<style>
	page {
		background: #efeff4;
	}

	.uni-list-cell {
		height: 150rpx;
		widht: 90%;

	}

	.uni-media-list-logo {
		width: 180upx;
		height: 140upx;
	}

	.uni-media-list-body {
		height: auto;
		justify-content: space-around;
	}

	.uni-media-list-text-top {
		height: 74upx;
		font-size: 28upx;
		overflow: hidden;
	}

	.uni-media-list-text-bottom {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}
</style>
